Skip to content

fix(kit): merge initialValue defaults when syncing client shared state#276

Merged
antfu merged 1 commit intomainfrom
antfu/fix-rpc-cleanup
Apr 1, 2026
Merged

fix(kit): merge initialValue defaults when syncing client shared state#276
antfu merged 1 commit intomainfrom
antfu/fix-rpc-cleanup

Conversation

@antfu
Copy link
Copy Markdown
Member

@antfu antfu commented Apr 1, 2026

Description

The client-side shared state currently replaces its state entirely with server values (state.mutate(() => serverState)), without merging the client's initialValue defaults. This means if the server state is missing a newly added field (e.g. commandShortcuts from stale persisted data), the client loses it — causing "Cannot set properties of undefined" errors.

This fix mirrors the server-side createStorage merge strategy ({ ...initialValue, ...savedValue }) on the client side, ensuring new default fields are always preserved when syncing with the server. This prevents the entire class of "new settings field is undefined" bugs.

closes #263

Linked Issues

closes #263
Alternative to #264

Additional context

As noted in #264, the proper fix is in the merge layer rather than adding per-field guards in UI components. The merge is applied in all three code paths where server state replaces client state: initial fetch, live update events, and the no-initialValue branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 1, 2026

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@276

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@276

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@276

@vitejs/devtools-rpc

npm i https://pkg.pr.new/@vitejs/devtools-rpc@276

@vitejs/devtools-self-inspect

npm i https://pkg.pr.new/@vitejs/devtools-self-inspect@276

commit: 586c6bb

@antfu antfu merged commit bd33f80 into main Apr 1, 2026
9 checks passed
@antfu antfu deleted the antfu/fix-rpc-cleanup branch April 1, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: Cannot set properties of undefined when saving keyboard shortcuts

1 participant